<template>
  <div class="flex-content">
    <swiper :autoplay="auto" :current="currentIndex" :circular="true" previous-margin="80rpx" next-margin="80rpx"
      :interval="3000" :duration="100" @change="swierChange">
      <swiper-item v-for="(item, index) in list" :key="index">
        <div :class="currentIndex === index ? 'slide-image active' : 'slide-image'" @click="jumpTo(item)">
          <div class="slide-head">
            <image :src="item.goodsCoverImg"></image>
          </div>
          <div class="slide-foot">
            <div>{{ item.goodsName }}</div>
            <div>{{ item.goodsIntro }}</div>
            <div class="flex-a"><span class="sell">￥{{ item.sellingPrice }}</span><span>￥{{ item.originalPrice }}</span>
            </div>
          </div>
        </div>
      </swiper-item>
    </swiper>
  </div>
</template>
    
<script lang="ts">
import Taro from '@tarojs/taro'
import { reactive, toRefs, onMounted } from 'vue';
import { getHotGoods } from '../../../api/index'
export default {
  setup() {
    const state = reactive({
      list: [],
      currentIndex: 0,
      auto: true
    });
    onMounted(() => {
      getHotGoods().then(res => {
        if (res.resultCode == 200) {
          state.list = res.data
        }
      })
      Taro.onAppHide(() => {
        state.auto = false
      })
    });
    const jumpTo = (item) => {
      Taro.navigateTo({ url: '/packageA/pages/productDetail/index?goodsId=' + item.goodsId });
    }
    const swierChange = (e) => {
      state.currentIndex = e.detail.current
    }
    return { ...toRefs(state), swierChange, jumpTo };
  }
};
</script>
<style lang="scss" >
.nut-swiper-item {
  line-height: 400px;

  img {
    width: 100%;
    height: 100%;
  }
}

.flex-content {
  // width: 90%;
  margin: -20rpx auto 0;
  box-sizing: border-box;
  padding: 0 10rpx;
}

.slide-image {
  position: absolute;
  height: 360rpx;
  width: 546rpx;
  border-radius: 15rpx;
  z-index: 5;
  opacity: 0.7;
  top: 18%;
  margin: 0 20rpx;
  background: #fff;
  padding: 20rpx 0;
  box-sizing: border-box;
  // border: 15rpx solid #BE0A01;

  .slide-head {
    height: 200rpx;
    text-align: center;

    image {
      width: 50%;
      height: 100%;
      margin: 0 auto;
    }
  }

  .slide-foot {
    div {
      word-break: keep-all;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      box-sizing: border-box;
      padding: 0 30rpx;
      font-size: 30rpx;
    }

    div:first-child {
      font-weight: bold;
    }

    div:nth-child(2) {
      color: #CDCDCD;
      margin: 5rpx 0;
    }

    div:last-child {
      color: #F25C26;

      span:last-child {
        color: gray;
        margin-left: 10rpx;
        text-decoration: line-through;
        font-size: 26rpx;
      }

      .sell {
        font-weight: bold;
        font-size: 30rpx;
      }
    }
  }
}

swiper {
  height: 530rpx;
}

.active {
  opacity: 1;
  z-index: 10;
  height: 500rpx;
  width: 546rpx;
  top: 4%;
  transition: all 0.2s ease-in 0s;

  .slide-head {
    height: 300rpx;
    text-align: center;
  }
}
</style>